# -*- coding: utf-8 -*-
from flask import Flask,jsonify,render_template
from flask_cors import CORS
import json, os

app = Flask(__name__)
CORS(app,  resources={r"/*": {"origins": "*"}})

@app.route('/')
def hello_world():
    return 'Hello World!'


@app.route('/api/graph')
def getGraph():
    print(os.getcwd())
    with open(r"..\src\data\graph.json",'r',encoding="utf8") as f:
        data = f.read()
    return data,200,{"Content-Type":"application/json","Access-Control-Allow-Origin":"*"}

@app.route('/api/stateage')
def getStateage():
    print(os.getcwd())
    with open(r"..\src\data\stateage.json",'r',encoding="utf8") as f:
        data = f.read()
    return data,200,{"Content-Type":"application/json","Access-Control-Allow-Origin":"*"}

@app.route('/api/data')
def getData():
    print(os.getcwd())
    with open(r"..\src\data\data.json",'r',encoding="utf8") as f:
        data = f.read()
    return data,200,{"Content-Type":"application/json","Access-Control-Allow-Origin":"*"}

@app.route('/index')
def index():
     return render_template('../public/index.html')

if __name__ == '__main__':
    app.run(port="5000",debug=True)